package com.check;

import cn.hutool.core.io.FileUtil;
import com.dto.config.IniDTO;
import com.utils.IniReader;
import com.utils.OSUtil;
import com.utils.PathUtil;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;

import java.io.File;
import java.io.IOException;

@Slf4j(topic = "配置信息类")
public class Check_Info {
    public static String NATIVE_LIBRARY_NAME;

    static {
        if (OSUtil.isWindows()== true) {
            try {
                NATIVE_LIBRARY_NAME = PathUtil.getExePath() + File.separator + "config.ini";
            } catch (IOException e) {
                e.printStackTrace();
            }
        } else {
            NATIVE_LIBRARY_NAME = PathUtil.getRunPath() + File.separator + "config.ini";
        }


    }

    @SneakyThrows
    public Check_Info() {

        File file = FileUtil.file(NATIVE_LIBRARY_NAME);
        IniReader reader = new IniReader(file);
        file = FileUtil.file(NATIVE_LIBRARY_NAME);
        reader = new IniReader(file);


        /*sftp*/
        IniDTO.setSftp_host(reader.getValue("config", "--sftp.host"));
        IniDTO.setSftp_path(reader.getValue("config", "--sftp.path"));
        IniDTO.setSftp_username(reader.getValue("config", "--sftp.username"));
        IniDTO.setSftp_password(reader.getValue("config", "--sftp.password"));
        IniDTO.setSftp_port(reader.getValue("config", "--sftp.port"));
        IniDTO.setHttpPort(reader.getValue("config", "--api.port"));


        log.info("读取配置文件成功");
    }
}
